# -*- encoding: utf-8 -*-
"""

PyCharm property函数的使用
2024年10月21日22时38分
by wenyang

文件主要内容:


"""
class Student(object):
    def __init__(self, name, age):
        self._name = name
        self._age = age

    def get_name(self):
        return self._name

    def set_name(self, name):
        self._name = name

    def del_name(self):
        self._name = None

    name = property(get_name, set_name, del_name)
class Student_one(object):
    def __init__(self, name, age):
        self._name = name
        self._age = age

    @property
    def Name(self):
        return self._name
    # 就是相当于Name = proterty(Name)  之后就是可以设置Name.setter Name.deleter

    @Name.setter
    def Name(self, name):
        self._name = name

    @Name.deleter
    def Name(self):
        self._name = None
def main():
    stu = Student("wenyang", 23)
    print(stu.name) # 会自动调用get_name方法
    stu.name = "hello world" # 会自动嗲用set_name方法
    print(stu.name)
    del stu.name
    print(stu.name)

    stu_one = Student_one("wenyang", 23)
    print(stu_one.Name)
    stu_one.Name = "hello world"
    print(stu_one.Name)
    del stu_one.Name
    print(stu_one.Name)


if __name__ == "__main__":
    main()
